<template>
  <van-nav-bar
      fixed
      title="修改密码"
      left-text="返回"
      left-arrow
      @click-left="onClickLeft"
  />
  <van-divider></van-divider>
  <van-divider></van-divider>
  <van-form @submit="onSubmit">
    <van-field
        v-model="oldPassword"
        type="password"
        name="旧密码"
        label="旧密码"
        placeholder="旧密码"
        :rules="[{ required: true, message: '请填写旧密码' }]"
    />
    <van-field
        v-model="password"
        type="password"
        name="新密码"
        label="新密码"
        placeholder="新密码"
        :rules="[{ required: true, message: '请填写新密码' }]"
    />
    <van-field
        v-model="rePassword"
        type="password"
        name="重复新密码"
        label="重复新密码"
        placeholder="请再次填写新密码"
        :rules="[{ required: true, message: '请再次填写新密码' }]"
    />
    <div style="margin: 16px;">
      <van-button round block type="primary" native-type="submit">
        提交
      </van-button>
    </div>
  </van-form>
</template>

<script>
import {Toast} from "vant";
import {updatePassword} from "@/api/user";

export default {
name: "UpdatePassword",
  data(){
    return {
      password:"",
      oldPassword: "",
      rePassword:""
    }
  },
  methods:{
    onSubmit(){
      if(this.rePassword != this.password){
        Toast.fail("两次密码不一致");
        return false
      }else {
        updatePassword(this.oldPassword,this.password).then((res)=>{
          Toast.success(res.msg)
        })
      }

    },
    onClickLeft(){
      history.back()
    },
  }
}
</script>

<style scoped>

</style>
